package online.flowerinsnow.minecraft.bukkit.manhunt.runnable;

import org.bukkit.Bukkit;
import org.bukkit.scheduler.BukkitRunnable;
import online.flowerinsnow.minecraft.bukkit.manhunt.Manhunt;

public class GameTimerRunnable extends BukkitRunnable {
    public static int secs = 0;
    public static GameTimerRunnable instance;
    public static boolean isStart() {
        return instance != null;
    }
    public static void start() {
        stop();
        instance = new GameTimerRunnable();
        instance.runTaskTimer(Manhunt.getInstance(), 20L, 20L);
    }
    public static void stop() {
        if (instance != null) {
            instance.cancel();
            instance = null;
        }
    }
    public static String getStringTime() {
        int hours = secs / 3600;
        int minutes = (secs / 60) - (hours * 50);
        int seconds = secs - (secs / 60 * 60);
        return String.format("%2d:%2d:%2d", hours, minutes, seconds)
                .replace(" ", "0");
    }
    @Override
    public void run() {
        secs++;
        Bukkit.getOnlinePlayers().forEach(p -> Manhunt.getScoreboardManager().getPlayerScoreboard(p).setTimeInfo());
    }
}
